package com.example.my_self_view.list

import android.graphics.Rect
import android.os.Bundle
import android.util.TypedValue
import android.view.View
import androidx.appcompat.app.AppCompatActivity
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.example.my_self_view.databinding.ActivityListBinding
import com.example.my_self_view.util.DataUtil

/**
 * @dsc     简介
 * @Author  LiWeiZhong
 * @Date    2025/1/20 11:15
 * @Version 1.0
 */
class ListActivity: AppCompatActivity() {

    private lateinit var mBinding: ActivityListBinding
    private val adapter by lazy { ProvinceListAdapter() }
    private var layoutManager: LinearLayoutManager? = null

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        mBinding = ActivityListBinding.inflate(layoutInflater)
        setContentView(mBinding.root)

        layoutManager = LinearLayoutManager(this)
        mBinding.provinceList.layoutManager = layoutManager
        mBinding.provinceList.adapter = adapter
        // 23个省，5个自治区，4个直辖市，2个特别行政区
        adapter.data = DataUtil.getProvinceList()
        mBinding.provinceList.addItemDecoration(object : RecyclerView.ItemDecoration() {
            override fun getItemOffsets(
                outRect: Rect,
                view: View,
                parent: RecyclerView,
                state: RecyclerView.State
            ) {
                outRect.top = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 5f, resources.displayMetrics).toInt()
                outRect.bottom = outRect.top
            }
        })
    }
}